import myAxios from '@/request'

// 用户注册
export const userRegister = async (params: any) => {
  return await myAxios.request({
    url: '/api/user/register',
    method: 'POST',
    data: params
  })
}
// 用户登录
export const userLogin = async (params: {
  username: string
  password: string
}) => {
  return await myAxios.request({
    url: '/api/user/login',
    method: 'POST',
    data: params
  })
}

// 获取当前用户信息
export const getUserInfo = async () => {
  return await myAxios.request({
    url: '/api/user/info',
    method: 'GET'
  })
}

// 更新用户信息
export const updateUserInfo = async (params: {
  nickname?: string
  avatar?: string
  phone?: string
}) => {
  return await myAxios.request({
    url: '/api/user/info',
    method: 'PUT',
    data: params
  })
}

// 更改密码
export const changePassword = async (params: {
  oldPassword: string
  newPassword: string
  confirmPassword: string
}) => {
  return await myAxios.request({
    url: '/api/user/password',
    method: 'PUT',
    data: params
  })
}

// 退出登录
export const userLogout = async () => {
  return await myAxios.request({
    url: '/api/user/logout',
    method: 'POST'
  })
}

// 获取用户地址列表
export const getUserAddresses = async () => {
  return await myAxios.request({
    url: '/api/user/addresses',
    method: 'GET'
  })
}

// 添加新地址
export const addUserAddress = async (params: {
  receiver: string
  phone: string
  province: string
  city: string
  district: string
  detail: string
  isDefault: boolean
}) => {
  return await myAxios.request({
    url: '/api/user/addresses',
    method: 'POST',
    data: params
  })
}
